package org.abettor.angleworm.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.abettor.angleworm.i18n.Translator;
import org.abettor.util.Environment;

/**
 * 读取服务条款的工具类
 * @author shawn
 *
 */
public abstract class AgreementReader
{
	public static String getAgreement()
	{
		InputStream is = null;
		try
		{
			String language = "en_US";
			Translator translator = Translator.getInstance();
			if(translator != null)
			{
				language = translator.getCurrentLanguage();
			}

			String path = Environment.getFilePath("conf/agreement." + language + ".txt");
			File file = new File(path);
			if(! file.exists())
			{
				path = Environment.getFilePath("conf/agreement.en_US.txt");
				file = new File(path);
			}

			is = new FileInputStream(file);
			int len = is.available();
			byte[] b = new byte[len];
			is.read(b);
			String val = new String(b, "UTF-8");
			return val;
		}
		catch (IOException e)
		{
			e.printStackTrace();
			return null;
		}
		finally
		{
			if(is != null)
			{
				try
				{
					is.close();
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
			}
		}
	}
}
